    /**************************************************************
    * 
    ***************************************************************/
void init_ultrasonic(void)
{
  #ifdef ping_mode == 0
  pinMode(ping_pw, INPUT);
  #endif
  pinMode(ping_rx, OUTPUT);
  digitalWrite(ping_rx, HIGH);//enabling ultrasonic sensor.
  //delay(1000);
} 
       /**************************************************************
    * 
    ***************************************************************/
unsigned int raw_ultrasonic(void) //Return the altitude exactly at the moment you request it... 
{
  unsigned int pulse_length=0; //declaring variable
  #ifdef ping_mode == 1
  static float average_pulse;
    //pulse_length=analogRead(2);
    average_pulse=(((float)average_pulse*.50)+(float)((float)analogRead(2)*.50));
    pulse_length=average_pulse;
  #else
  Serial.println("hi!");
   pinMode(US_ALT, OUTPUT);
  digitalWrite(US_ALT, LOW);
  delayMicroseconds(2);
  digitalWrite(US_ALT HIGH);
  delayMicroseconds(5);
  digitalWrite(US_ALT, LOW);
  pinMode(ping, INPUT);
  pulse_length = pulseIn(US_FRONT, HIGH);
  pulse_length = pulse_length/147;
  #endif
    
    return pulse_length;
}
         /**************************************************************
    * 
    ***************************************************************/
unsigned int pulse_ultrasonic(unsigned int refresh_rate)//Returns the altitude with the specified refresh rate in milliseconds
{
  if((millis() - timer_ultrasonic) > refresh_rate)
  {
    altitude=raw_ultrasonic();
    timer_ultrasonic=millis();
  }  
  return altitude;
}  

unsigned int raw_forward_us( )
{
  unsigned int pulse_length;
  pinMode(US_FRONT, OUTPUT);
  digitalWrite(US_FRONT, LOW);
  delayMicroseconds(2);
  digitalWrite(US_FRONT, HIGH);
  delayMicroseconds(5);
  digitalWrite(US_FRONT, LOW);
  pinMode(US_FRONT, INPUT);
  pulse_length = pulseIn(US_FRONT, HIGH);
  // TODO: consider shifting left 6 bits instead
  return pulse_length/58;
}

unsigned int pulse_forward_us( unsigned int refresh_rate )
{
  if( ( millis( ) - timer_ultrasonic_forward ) > refresh_rate )
  {
    forward_distance = raw_forward_us( );
    timer_ultrasonic_forward = millis( );
  }
  
  return forward_distance;
}

unsigned int raw_side_us( )
{
  unsigned int pulse_length;
  pinMode(US_LEFT, OUTPUT);
  digitalWrite(US_LEFT, LOW);
  delayMicroseconds(2);
  digitalWrite(US_LEFT, HIGH);
  delayMicroseconds(5);
  digitalWrite(US_LEFT, LOW);
  pinMode(US_LEFT, INPUT);
  pulse_length = pulseIn(US_LEFT, HIGH);
  // TODO: consider shifting left 6 bits instead
  return pulse_length/58;
}

unsigned int pulse_side_us( unsigned int refresh_rate )
{
  if( ( millis( ) - timer_ultrasonic_forward ) > refresh_rate )
  {
    forward_distance = raw_forward_us( );
    timer_ultrasonic_forward = millis( );
  }
  
  return forward_distance;
}
